package com.woniuxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.entity.Order;
import com.woniuxy.provider.OrderProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;

/**
 * 订单Mapper接口
 */
public interface OrderMapper extends BaseMapper<Order> {

    /**
     * @param order:
     * @return: List<Orderrder>
     * @description:根据条件查询订单
     * @date: 2021/8/12 10:29
     * @author: 魏炳豪
     */
    @SelectProvider(type = OrderProvider.class, method = "getByCondition")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "order_number",property = "orderNum"),
            @Result(column = "order_time",property = "orderTime"),
            @Result(column = "user_id",property = "userId"),
            @Result(column = "phone",property = "phoneNum"),
            @Result(column = "address",property = "address"),
            @Result(column = "price",property = "price"),
            @Result(column = "reciever",property = "reciever"),
            @Result(column = "status",property = "status"),
            @Result(property = "user",column = "id", many = @Many(fetchType = FetchType.LAZY, select = "com.woniuxy.mapper.UserMapper.selectById")),
    })
    List<Order> getByCondition(Order order);



    /**
     * @return: java.util.List<com.woniuxy.entity.Order>
     * @description:查询所有订单
     * @date: 2021/8/12 10:32
     * @author: 魏炳豪
     */
    @Select("SELECT * FROM gfr_order")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "order_number",property = "orderNum"),
            @Result(column = "order_time",property = "orderTime"),
            @Result(column = "user_id",property = "userId"),
            @Result(column = "phone",property = "phoneNum"),
            @Result(column = "address",property = "address"),
            @Result(column = "price",property = "price"),
            @Result(column = "reciever",property = "reciever"),
            @Result(column = "status",property = "status"),
            @Result(property = "user",column = "user_id", many = @Many(fetchType = FetchType.LAZY, select = "com.woniuxy.mapper.UserMapper.selectById")),
    })
    List<Order> getAllOrders();

    @Select("update gfr_order  set  status=#{status} where order_number=#{number} and user_id=#{userid}")
    void update(String number,int userid,int status);

    @Select("update gfr_order  set `status`=#{status} , is_review=#{isReview} where id=#{id}")
    void update1(int id, String isReview,Integer status);

    @Select("select*from gfr_order where user_id=#{userId} and order_number=#{number}")
    Order getByOrder(int userId,String number);
}

